﻿using System;

namespace diantou.web.ajax.enterprise
{
    /// <summary>
    /// 企业用户权限调用
    /// </summary>
    abstract class permissionHandle<callType> : userHandle<callType>
        where callType : permissionHandle<callType>
    {
        /// <summary>
        /// 当前用户
        /// </summary>
        private diantou.examDataAccess.enterprise enterprise;
        /// <summary>
        /// 当前用户
        /// </summary>
        protected diantou.examDataAccess.enterprise currentEnterprise
        {
            get
            {
                if (enterprise == null)
                {
                    if (currentUser != null) enterprise = examDataAccess.clientCache.Enterprise[currentUser.Id];
                    if (enterprise == null) enterprise = diantou.examDataAccess.enterprise.NullEnterprise;
                }
                return enterprise != diantou.examDataAccess.enterprise.NullEnterprise ? enterprise : null;
            }
        }
        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        protected override bool loadHeader()
        {
            if (base.loadHeader())
            {
                if (sessionUser.IsEnterprisePermission) return true;
                AjaxResponse(new fastCSharp.code.cSharp.webView.errorPath { ErrorPath = diantou.dataModel.path.pub.EnterpriseLogin });
            }
            return false;
        }
        /// <summary>
        /// 清除数据
        /// </summary>
        protected override void clear()
        {
            base.clear();
            enterprise = null;
        }
    }
}
